//
//  MCTrainPlanDetailVc.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/19.
//

import UIKit

class MCTrainPlanDetailVc: MCBaseVc {
    
    let trainPlanDetailIdentifier = "trainPlanDetailIdentifier"
    
    let actionMainchieyIdentifier = "actionMainchieyIdentifier"
    
    let actionKeyPointIdentifier = "actionKeyPointIdentifier"
    
    
    var playerView:UIView?
    
    var baseScrollView:UIScrollView?
    
    //英文标题
    var titleEnLabel:QMUILabel?
    
    //中文标题
    var titleCnLabel:QMUILabel?
    
    //收藏标签
    var collectionImageBtn:QMUIButton?
    
    //分享标签
    var shareLabelBtn:QMUIButton?
    
    //文字标签
    var textLabelCollectionView:UICollectionView?
    

    
    //对称视图
    var symmetryCollectionView:UICollectionView?
    
    //肌肉-副标题
    var mainMuscleSubTitleLabel:QMUILabel?
    
    //锻炼肌肉
    var mainMuscleCollectionView:UICollectionView?
    
    //机械
    var machineryCollectionView:UICollectionView?
    
    //重点
    var keynoteCollectionView:UICollectionView?
    
    //动作步骤
    var actionStepsInfoLabel:QMUILabel?
    
    //呼吸
    var breatheInfoLabel:QMUILabel?
    
    //动作频率
    var rateInfoLabel:QMUILabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        loadWithSubViews()
    }
    
    func loadWithSubViews() -> Void {
        baseScrollView = UIScrollView.init(frame:self.view.frame)
        self.view.addSubview(baseScrollView!)
        baseScrollView?.backgroundColor = UIColor.white
        baseScrollView?.alwaysBounceVertical = true
        baseScrollView?.showsVerticalScrollIndicator = false
        baseScrollView?.contentSize = CGSize(width: UIScreen.main.bounds.size.width, height: 14000)
        
        //播放视频
        self.playerView = UIView.init()
        playerView?.backgroundColor = UIColor.qmui_random()
        self.baseScrollView?.addSubview(self.playerView!)
        self.playerView?.snp.makeConstraints { make in
            make.left.equalTo(baseScrollView!.snp.left).offset(0)
            make.right.equalTo(baseScrollView!.snp.right).offset(0)
            make.top.equalTo(baseScrollView!.snp.top).offset(0)
            make.width.equalTo(self.view.snp.width)
            make.height.equalTo(10)
        }
        
        //英文
        self.titleEnLabel = QMUILabel.init()
        self.titleEnLabel?.text = "Dynamic Hip Bridge"
        self.baseScrollView?.addSubview(self.titleEnLabel!)
        self.titleEnLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
            make.top.equalTo(self.playerView!.snp.bottom).offset(10)
            make.right.equalTo(self.baseScrollView!.snp.right).offset(-15)
        })
        
        //中文
        self.titleCnLabel = QMUILabel.init()
        self.titleCnLabel?.text = "神父傻姑娘写喜剧"
        self.titleCnLabel?.font = UIFont.systemFont(ofSize: 30)
        self.titleCnLabel?.textColor = UIColor.qmui_color(withHexString: "#333333")
        self.baseScrollView?.addSubview(self.titleCnLabel!)
        self.titleCnLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
            make.top.equalTo(self.titleEnLabel!.snp.bottom).offset(5)
            
        })
        
        
        //分享
        self.shareLabelBtn = QMUIButton.init()
        self.shareLabelBtn?.setImage(UIImage(named: "common_blue_image"), for: .normal)
        self.baseScrollView?.addSubview(self.shareLabelBtn!)
        self.shareLabelBtn?.snp.makeConstraints { make in
            make.right.equalTo(self.baseScrollView!.snp.right).offset(-15)
            make.centerY.equalTo(self.titleCnLabel!.snp.centerY).offset(0)
            make.width.height.equalTo(40)
        }
        
        //收藏
        self.collectionImageBtn = QMUIButton.init()
        self.collectionImageBtn?.setImage(UIImage(named: "common_blue_image"), for: .normal)
        self.baseScrollView?.addSubview(self.collectionImageBtn!)
        self.collectionImageBtn?.snp.makeConstraints { make in
            make.centerY.equalTo(self.titleCnLabel!.snp.centerY).offset(0.0)
            make.right.equalTo(self.shareLabelBtn!.snp.left).offset(-20)
            make.height.width.equalTo(40)
        }
        
        //动作步骤文字
        let actionStepsTextLabel:QMUILabel = QMUILabel.init()
        actionStepsTextLabel.text = "介绍"
        actionStepsTextLabel.font = UIFont.systemFont(ofSize: 15)
        actionStepsTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        self.baseScrollView?.addSubview(actionStepsTextLabel)
        actionStepsTextLabel.snp.makeConstraints { make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
            make.top.equalTo(self.titleCnLabel!.snp.bottom).offset(10)
        }
        
        actionStepsInfoLabel = QMUILabel.init()
        actionStepsInfoLabel?.text = "1. 平躺在地面上，双手置于身体两侧，并微微往脚的方向触碰，双脚及膝盖距离大约一扎的距离，大腿与小腿呈90度，腰部贴住地面，屁股夹紧，做骨盆后卷的动作\n2.在呼气时臀大肌发力，将我们的臀部抬起，使我们的膝关节，髋关节，肩峰，呈一条直线\n3.然后将脚尖抬起，再将脚尖与膝关节同时打开，保持3秒钟，然后在吸气中缓慢落下，回到起始位置"
        actionStepsInfoLabel?.font = UIFont.systemFont(ofSize: 13)
        actionStepsInfoLabel?.numberOfLines = 0
        actionStepsInfoLabel?.textColor = UIColor.qmui_color(withHexString: "#666666")
        self.baseScrollView?.addSubview(actionStepsInfoLabel!)
        self.actionStepsInfoLabel?.snp.makeConstraints { make in
            make.left.equalTo(actionStepsTextLabel.snp.left).offset(0)
            make.top.equalTo(actionStepsTextLabel.snp.bottom).offset(5)
            make.right.equalTo(self.view.snp.right).offset(-15)
           
        }
         
        
        //对称视图文字
        let symmetryTextLabel:QMUILabel = QMUILabel.init()
        symmetryTextLabel.text = "相关训练动作"
        symmetryTextLabel.font = UIFont.systemFont(ofSize: 15)
        symmetryTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        self.baseScrollView?.addSubview(symmetryTextLabel)
        symmetryTextLabel.snp.makeConstraints { make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
            make.top.equalTo(self.actionStepsInfoLabel!.snp.bottom).offset(10)
        }
        
        //对称视频collection
        let symmetryFlowLayout = UICollectionViewFlowLayout.init()
        symmetryFlowLayout.scrollDirection = .horizontal
        self.symmetryCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: symmetryFlowLayout)
        self.symmetryCollectionView?.dataSource = self
        self.symmetryCollectionView?.delegate = self
        
        self.baseScrollView?.addSubview(self.symmetryCollectionView!)
        self.symmetryCollectionView?.snp.makeConstraints { make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(16)
            make.top.equalTo(symmetryTextLabel.snp.bottom).offset(10)
            make.width.equalTo(UIScreen.main.bounds.size.width - 30)
            make.height.equalTo(150)
        }
        
      //  self.symmetryCollectionView?.register(MCActionCollectionViewCell.self, forCellWithReuseIdentifier: trainPlanDetailIdentifier)
        
        
        //主要锻炼肌肉文字
        let mianMuscleTextLabel:QMUILabel = QMUILabel.init()
        mianMuscleTextLabel.text = "机械推荐"
        mianMuscleTextLabel.font = UIFont.systemFont(ofSize: 15)
        mianMuscleTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        self.baseScrollView?.addSubview(mianMuscleTextLabel)
        mianMuscleTextLabel.snp.makeConstraints { make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
            make.top.equalTo(self.symmetryCollectionView!.snp.bottom).offset(10)
        }
        
        
        //肌肉-collectionView
        let mainMuscleFlowLayout = UICollectionViewFlowLayout.init()
        mainMuscleFlowLayout.scrollDirection = .horizontal
        self.mainMuscleCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: mainMuscleFlowLayout)
        self.mainMuscleCollectionView?.dataSource = self
        self.mainMuscleCollectionView?.delegate = self
        
        self.baseScrollView?.addSubview(self.mainMuscleCollectionView!)
        self.mainMuscleCollectionView?.snp.makeConstraints { make in
            make.left.equalTo(self.baseScrollView!.snp.left).offset(16)
            make.top.equalTo(mianMuscleTextLabel.snp.bottom).offset(10)
            make.width.equalTo(UIScreen.main.bounds.size.width - 30)
            make.height.equalTo(150)
        }
        
      //  self.mainMuscleCollectionView?.register(MCActionCollectionViewCell.self, forCellWithReuseIdentifier: trainPlanDetailIdentifier)
        
        
//        //机械文字
//        let machineryTextLabel:QMUILabel = QMUILabel.init()
//        machineryTextLabel.text = "机械"
//        machineryTextLabel.font = UIFont.systemFont(ofSize: 15)
//        machineryTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
//        self.baseScrollView?.addSubview(machineryTextLabel)
//        machineryTextLabel.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
//            make.top.equalTo(self.mainMuscleCollectionView!.snp.bottom).offset(10)
//        }
//
//        //机械
//        let machineryFlowLayout = UICollectionViewFlowLayout.init()
//        machineryFlowLayout.scrollDirection = .horizontal
//        self.machineryCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: machineryFlowLayout)
//        self.machineryCollectionView?.dataSource = self
//        self.machineryCollectionView?.delegate = self
//
//        self.baseScrollView?.addSubview(self.machineryCollectionView!)
//        self.machineryCollectionView?.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(16)
//            make.top.equalTo(machineryTextLabel.snp.bottom).offset(10)
//            make.width.equalTo(UIScreen.main.bounds.size.width - 30)
//            make.height.equalTo(150)
//        }
//
//        self.machineryCollectionView?.register(MCMaichineCollectionCell.self, forCellWithReuseIdentifier: actionMainchieyIdentifier)
//
//        //注意重点-文字
//        let keyNoteTextLabel:QMUILabel = QMUILabel.init()
//        keyNoteTextLabel.text = "注意重点"
//        keyNoteTextLabel.font = UIFont.systemFont(ofSize: 15)
//        keyNoteTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
//        self.baseScrollView?.addSubview(keyNoteTextLabel)
//        keyNoteTextLabel.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
//            make.top.equalTo(self.machineryCollectionView!.snp.bottom).offset(10)
//        }
//
//        //注意重点
//        let keyNoteFlowLayout = UICollectionViewFlowLayout.init()
//        keyNoteFlowLayout.scrollDirection = .horizontal
//        self.keynoteCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: keyNoteFlowLayout)
//        self.keynoteCollectionView?.dataSource = self
//        self.keynoteCollectionView?.delegate = self
//
//        self.baseScrollView?.addSubview(self.keynoteCollectionView!)
//        self.keynoteCollectionView?.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(16)
//            make.top.equalTo(keyNoteTextLabel.snp.bottom).offset(10)
//            make.width.equalTo(UIScreen.main.bounds.size.width - 30)
//            make.height.equalTo(150)
//        }
//
//        self.keynoteCollectionView?.register(MCKeyPointCollectionCell.self, forCellWithReuseIdentifier: actionKeyPointIdentifier)
//
//
//        //动作步骤文字
//        let breatheTextLabel:QMUILabel = QMUILabel.init()
//        breatheTextLabel.text = "呼吸方式"
//        breatheTextLabel.font = UIFont.systemFont(ofSize: 15)
//        breatheTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
//        self.baseScrollView?.addSubview(breatheTextLabel)
//        breatheTextLabel.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
//            make.top.equalTo(self.actionStepsInfoLabel!.snp.bottom).offset(10)
//        }
//
//        breatheInfoLabel = QMUILabel.init()
//        breatheInfoLabel?.text = "用力时呼气，放松时吸气"
//        breatheInfoLabel?.font = UIFont.systemFont(ofSize: 13)
//        breatheInfoLabel?.numberOfLines = 0
//        breatheInfoLabel?.textColor = UIColor.qmui_color(withHexString: "#666666")
//        self.baseScrollView?.addSubview(breatheInfoLabel!)
//        self.breatheInfoLabel?.snp.makeConstraints { make in
//            make.left.equalTo(breatheTextLabel.snp.left).offset(0)
//            make.top.equalTo(breatheTextLabel.snp.bottom).offset(5)
//            make.right.equalTo(self.view.snp.right).offset(-15)
//
//        }
//
//        //锻炼频率文字
//        let rateTextLabel:QMUILabel = QMUILabel.init()
//        rateTextLabel.text = "锻炼频率"
//        rateTextLabel.font = UIFont.systemFont(ofSize: 15)
//        rateTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
//        self.baseScrollView?.addSubview(rateTextLabel)
//        rateTextLabel.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
//            make.top.equalTo(self.breatheInfoLabel!.snp.bottom).offset(10)
//        }
//
//        rateInfoLabel = QMUILabel.init()
//        rateInfoLabel?.text = "建议每组10次，每次30分钟"
//        rateInfoLabel?.font = UIFont.systemFont(ofSize: 13)
//        rateInfoLabel?.numberOfLines = 0
//        rateInfoLabel?.textColor = UIColor.qmui_color(withHexString: "#666666")
//        self.baseScrollView?.addSubview(rateInfoLabel!)
//        self.rateInfoLabel?.snp.makeConstraints { make in
//            make.left.equalTo(rateTextLabel.snp.left).offset(0)
//            make.top.equalTo(rateTextLabel.snp.bottom).offset(5)
//            make.right.equalTo(self.view.snp.right).offset(-15)
//
//        }
//
//        //基础动作文字
//        let basicActionsTextLabel:QMUILabel = QMUILabel.init()
//        basicActionsTextLabel.text = "基础动作"
//        basicActionsTextLabel.font = UIFont.systemFont(ofSize: 15)
//        basicActionsTextLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
//        self.baseScrollView?.addSubview(basicActionsTextLabel)
//        basicActionsTextLabel.snp.makeConstraints { make in
//            make.left.equalTo(self.baseScrollView!.snp.left).offset(15)
//            make.top.equalTo(self.rateInfoLabel!.snp.bottom).offset(10)
//        }
    }
    
}

extension MCTrainPlanDetailVc:UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
   
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 200, height: 150)
    }
    
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        //        if collectionView == self.machineryCollectionView {
        //            let cell:MCMaichineCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: actionMainchieyIdentifier, for: indexPath) as! MCMaichineCollectionCell
        //            cell.backgroundColor = UIColor.cyan
        //            return cell
        //        }else if collectionView == self.keynoteCollectionView {
        //            let cell:MCKeyPointCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: actionKeyPointIdentifier, for: indexPath) as! MCKeyPointCollectionCell
        //            cell.backgroundColor = UIColor.red
        //            return cell
        //        } else{
        //            let cell:MCActionCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: trainPlanDetailIdentifier, for: indexPath) as! MCActionCollectionViewCell
        //            cell.backgroundColor = UIColor.qmui_random()
        //            return cell
        //        }
        //
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
        return cell
    }
    
}
